<?php
class OrderAction extends BaseAction{
	function _initialize(){
		parent::_initialize();
		$session = $_SESSION['LOTUSHER'];
		if(empty($session['uid']) ||  empty($session['last_time'])){
			window_location(U('Log/index'));
			exit();
		}
	}
	function index(){
		$this->seo_title = "订单记录";
		$where['user_id'] = $_SESSION['LOTUSHER']['uid'];
		$dao = M("OrderData");
		$count = $dao->where($where)->count();
		if($count){
			import ( "@.ORG.Page" );
			$listRows =  !empty($cat['pagesize']) ? $cat['pagesize'] : 12;
			$page = new Page ( $count, $listRows );	
			$this->pages = $page->show();			
			$this->list = $dao->where($where)->order("order_id DESC")->limit($page->firstRow . ',' . $page->listRows)->select();
		}		
		
		$this->display();
	}
	function add(){
		$data = $_POST;
		foreach ($data as $k=>$v){
			if(is_array($v)){
				$data[$k] = implode(",", $v);
			}
		}
		$data['order_id'] = date("YmdHis",time());
		$data['user_id'] = $_SESSION['LOTUSHER']['uid'];
		$data['status'] = 1;//新订单
		$data['create_time'] = time();
		$data['lang'] = 1;
		$dao = M("OrderData");
		$r = $dao->add($data);
		if($r){
			$this->success('提交成功',U('Order/detail',array('id'=>$r)));
		}else{
			$this->success('提交失败');
		}
	}
	function detail(){
		$this->od = M("OrderData")->find($_GET['id']);
		
		$this->display();
	}
	
}
?>